package com.rx.substation.dao;

import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.*;

import com.rx.substation.domain.Inspection;
import com.rx.substation.provider.OrderProvider;

public interface MonthQCInspectionDAO {
	@Select("select * from qcInspection where checkTime>=#{start} and checkTime<=#{end} order by stationCode")
	List<Map<String,Object>> getMonthQCInspection(@Param("start")String start, @Param("end")String end);
	
	@Select("select deduct from qcInspection where stationCode = #{stationCode}")
	Double getDeductByStation(@Param("stationCode")String stationCode);
	
	@Insert("insert into qcInspection (stationCode,stationName,deduct,checkTime,checkPerson,mark,detailId) values "
			+ "(#{stationCode},#{stationName},#{deduct},#{checkTime},#{checkPerson},#{mark},#{detailId})")
	void saveDeductScore(Map<String, Object> deductMap);

	
	@SelectProvider(type = OrderProvider.class, method = "findDeductByConditions")
	List<Map<String,Object>> findDeductByConditions(@Param("runUnitId")String runUnitId,@Param("citys")String citys,
		@Param("start")String start,@Param("end")String end,@Param("stations")String stations);

	@Select("select * from qcInspection2 where detailId = #{detailId}")
	List<Map<String,Object>> findDeductByDetailId(@Param("detailId")String detailId);

	@Insert("insert into qcInspection2 (detailId,checkWorkId,score,detailMark,detail) values "
			+ "(#{detailId},#{checkWorkId},#{score},#{detailMark},#{detail})")
    void saveDeductDetail(Map<String, Object> detailMap);

	@Select("select deduct from qcInspection where detailId = #{detailId}")
	Double findTotalDeduct(@Param("detailId")String detailId);

	@Delete("delete from qcInspection where detailId = #{detailId}")
    void deleteDeduct(@Param("detailId")String detailId);

	@Delete("delete from qcInspection2 where detailId = #{detailId}")
	void deleteDetailId(@Param("detailId")String detailId);


	@Update("update qcInspection set stationCode = #{stationCode},stationName = #{stationName},deduct = #{deduct},checkTime = #{checkTime},checkPerson = #{checkPerson},mark = #{mark}" +
			"where detailId = #{detailId}")
	void updateDeductScore(Map<String, Object> deductMap);

	@Update("update qcInspection set detail = #{detail},score = #{score},detailMark = #{detailMark}" +
			"where detailId = #{detailId} and checkWorkId = #{checkWorkId}")
	void updateDeductDetail(Map<String, Object> detailMap);

	@Select("select checkPerson from qcInspection where detailId = #{detailId}")
	String findCheckPerson(@Param("detailId")String detailId);
}
